<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: export.php,v $ 
 * $Date: 2005/08/31 10:13:46 $ 
 * $Revision: 1.2 $ 
 * 
 * ********* CVS HEADER ********* 
 */
function get_table_content_fast($table, $add_query = '')
{
	global $sql_serveur,$sql_login,$sql_pass,$sql_base,$sql_nb_requete;
    $cnx = @mysql_connect($sql_serveur,$sql_login,$sql_pass) or die ("Connexion au serveur $sql_serveur impossible");
    $base = @mysql_select_db($sql_base) or die ("Connexion &agrave; la base $sql_base impossible");
    $return = '';
    $result = mysql_query('SELECT * FROM ' . $table . $add_query) or rportalerreur('SELECT * FROM ' . $table . $add_query,"?op=");
    if ($result != false) {
    
        @set_time_limit(1200); // 20 Minutes

        // Checks whether the field is an integer or not
        for ($j = 0; $j < mysql_num_fields($result); $j++) {
            $field_set[$j] = mysql_field_name($result, $j);
            $type          = mysql_field_type($result, $j);
            if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' ||
                $type == 'bigint'  ||$type == 'timestamp') {
                $field_num[$j] = true;
            } else {
                $field_num[$j] = false;
            }
        } // end for

        // Get the scheme
        if (isset($GLOBALS['showcolumns'])) {
            $fields        = implode(', ', $field_set);
            $schema_insert = "INSERT INTO $table ($fields) VALUES (";
        } else {
            $schema_insert = "INSERT INTO $table VALUES (";
        }
        
        $field_count = mysql_num_fields($result);

        $search  = array("\x0a","\x0d","\x1a"); //\x08\\x09, not required
        $replace = array("\\n","\\r","\Z");


        while ($row = mysql_fetch_row($result)) {
            for ($j = 0; $j < $field_count; $j++) {
                if (!isset($row[$j])) {
                    $values[]     = 'NULL';
                } else if (!empty($row[$j])) {
                    // a number
                    if ($field_num[$j]) {
                        $values[] = $row[$j];
                    }
                    // a string
                    else {
                        $values[] = "'" . str_replace($search, $replace, addslashes($row[$j])) . "'";
                    }
                } else {
                    $values[]     = "''";
                } // end if
            } // end for

            $insert_line = $schema_insert . implode(',', $values) . ')';
            unset($values);

            // Call the handler
            $return.=$insert_line."\n";
        } // end while
    } // end if ($result != false)
    @mysql_free_result($result);
	@mysql_close($cnx);
    return $return;
}
?>